/*
 * create:2016年5月6日 下午1:23:07
 * author:wangds  
 */
package com.cxkj.shop.biz.cart;

import java.util.Collection;
import java.util.Map;

import javax.servlet.http.HttpSession;

import com.cxkj.shop.biz.AbstractBaseDeliveryHttpInteractionBusiness;
import com.cxkj.shop.model.shoppingcart.CommodityItem;
import com.cxkj.shop.model.shoppingcart.ShoppingCart;
import com.cxkj.shop.model.shoppingcart.ShoppingCartUtils;
import com.cxkj.shop.utils.BusinessUtils;

import net.wangds.utilities.lang.StringUtils;

/**
 * .
 * @author wangds
 *
 */
public class Add1f1Business extends AbstractBaseDeliveryHttpInteractionBusiness<Map<String,Object>, Boolean>{

  /*
   * @see com.cxkj.shop.biz.AbstractBaseDeliveryHttpInteractionBusiness#processBiz(java.lang.Object)
   * @author wangds 2016年5月6日 下午1:23:45.
   */
  @Override
  protected Boolean processBiz(Map<String, Object> param) throws Exception {
    boolean res = false;
    HttpSession ssn = BusinessUtils.getHttpSessionFromHttpBusiness(this);
    ShoppingCart cart = BusinessUtils.getShoppingCartFromSession(ssn);
    
    if(!cart.isOfo()){
      return res;
    }
    
    String commodityId = String.valueOf(param.get("commodityId"));
    
    Collection<CommodityItem> cos = ShoppingCartUtils.fetchCommodities(cart);
    for(CommodityItem co:cos){
      res = StringUtils.equals(co.getCommodityId(),commodityId);
      if(res){
        cart.setOfo(false);
        co.setFreeType(CommodityItem.TYPE_ONE_FREE_ONE);
        break;
      }
    }
    
    return res;
  }

}
